package com.ews.onlineexchange.service;

import java.util.Date;
import java.util.List;

import javax.enterprise.inject.Model;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import com.ews.onlineexchange.model.Bulletin;

@Model
public class UnoveredAndPassedBulletinList extends EntityQuery<Bulletin> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public UnoveredAndPassedBulletinList() {
		setOrder("createDate DESC");
	}

	@Override
	protected List<Predicate> getRestrictions(CriteriaBuilder cb, Root<Bulletin> entity) {		
		List<Predicate> restrictions = super.getRestrictions(cb, entity);
		restrictions.add(cb.isFalse(entity.<Boolean>get("over")));
		restrictions.add(cb.isTrue(entity.<Boolean>get("auditResult")));
		restrictions.add(cb.lessThan(entity.<Date>get("chooseTime"), new Date()));
		return restrictions;
	}
	
}
